Creating flowcharts or conceptual frameworks is a commonly used tool in empirical research. We can create beautifully designed vector flowcharts using DiagrammeR and grViz.

require("DiagrammeR")
## Loading required package: DiagrammeR
grViz("
      
digraph boxes_and_circles {

  # add note statement
  node [shape = circle
        fontname = Arial
        penwidth = 2.0]
  A; B; C; D; E; F
  
  node [shape = box]
  1; 2; 3; 4; 5; 6; 7; 8
  
  # add edge statements
  # edge [arrowhead = diamond]
  A -> 1; B -> 2; B -> 3; B -> 4; 
  C -> A; 1 -> D; E -> A; 2 -> 4;
  1 -> 5; 1 -> F; E -> 6; 4 -> 6; 
  5 -> 7; 6 -> 7; 3 -> 8[label = 'a label!'
                          fontname = Times]
  
  # add a graph statement
  graph [nodesep = 0.5]
  
}
      
")

The initial statement digraph boxes_and_circles is for a directed graph in the DOT language. comment lines begin with a # sign. These lines are disregarded.

node [shape = circle] states that all the following nodes to be defined will have the shape of a circle, it could be changed into box. A; B; C; D; E; F are defining the IDs of each node and calling the grViz function repeatedly, and multiple statements can be placed on a single line, separated by a ‘;’.

Then you can add the directions and relationships of these nodes by using -> and each separated by a ;. In order to change a range of properties for the graph, you can add a graph statement. graph [nodesep = 0.1] property modifies the separation distance between nodes.

  • change the fonts by adding fontname = Arial in square brackets.
  • change the stroke width of the nodes by penwidth = 2.0 in square brackets
  • change the appearance of arrows by arrowhead = diamond in square brackets
  • add the label for edges
mermaid("
        graph LR
        A --> B
        ", height = 200)